﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.XPath;

namespace HtmlExtractor.XPathOutput
{
    public class OneOneCompositeProcessor : XmlDocOutputPathProcessor
    {
        public OneOneCompositeProcessor():base()
        {}
        public OneOneCompositeProcessor(IGrouping<List<string>, IPageItem> inputData)
            : base(inputData)
        { }
           
        public override bool GetResult(ref XDocument outputData)
        {
            base.GetResult(ref outputData);
            if (InputData.Key.Count> 1 && InputData.Count() == 1)
            {
                CompositeItem comItem = InputData.Single() as CompositeItem;
                foreach (SimpleItem simple in comItem)
                {
                    EvaluateXPath(ref outputData, simple.OutputPath, simple.Value);
                }
                return true;
            }
            return false;
        }
    }
}
